<?php
namespace control;

//管理员后台 - 会计电子档案
class accountElecFileClass extends adIndexClass
{
    private const page  = 'accountElecFile'; # 权限
    private const table = 'account_elect_file'; # 数据表
    private const title = '会计电子档案';
    private static string $idColloection;

    /**
     * 字段初始化
     */
    public function fieldInit($fun): array
    {
        switch ($fun) {
            default:
                $tr = [
                    'name'          => [
                        'name'  => "名称",
                        'width' => 300,
                        'sort' => 1,
                    ],
                    'size'  => [
                        'name'  => '大小',
                        'width' => 300,
                        'sort' => 1,
                    ],
                    'time'         => [
                        'name'  => '创建时间',
                        'width' => 300,
                        'sort' => 1,
                    ],
                    'stid'          => [
                        'name'  => '编辑人',
                        'width' => 300,
                    ],
                    'opt'          => [
                        'name'  => '操作',
                        'width' => 300,
                    ]
                ];
        }
        return $tr;
    }

    /*列表页-查询条件*/
    public function homeOptions($isAsync = true, $data = [])
    {
        $fileId = isset($data['fileId']) && $data['fileId'] ? $data['fileId'] : $this->post('fileId');
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "文件名" => text(array("name" => "name")).
                        hidden(["name" => "pid", 'value'=> $this->get('pid') ?? 1]).
                        hidden(["name" => "fileId", 'value'=> $fileId]),
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /*成本表列表-查询条件*/
    public function home()
    {
        $fileId = self::getId();
        $pid = $this->get('pid') ?? 1;
        $html = $this->homeOptions(false, ['fileId' => $fileId]);
        //控件
        $button = '';
        $fileId = self::getId();
        if ($this->power(self::page, "edit")) {
            $button .= "<span class='spanButton li-btn-blue-bg' onclick=\"document.{$fileId}form.img.click()\">上传文件</span>\n";
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'editPage', {'id': '".self::getNo()."', 'pid': '$pid' })\">新建文件夹</span>\n";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'del'})\">删除</span>\n";
        }
        if ($this->power(self::page, "edit")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'move'})\">移动</span>\n";
        }
        //返回
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button, searchOption: "{fileId:'$fileId'}")).$this->style();
    }

    /*成本表列表-查询结果*/
    public function homeSearch()
    {
        $pid = $this->post('pid');
        $idColloection =  $this->staffCombination(true);
        $where = " if(selector is null,'1=1',((concat(',',replace(selector,';',','),',') regexp concat(',',replace('{$idColloection}',',',',|,'),','))>0 OR stid = '".self::$stid."'))";
        $like = [
            'name' => $this->post('name'),
        ];
        $where   .= search(["like" => $like])." and coid = '".self::$coid."'";
        // 判断是否是搜索
        $where .= $like['name'] ? '' : " AND `pid` = '$pid' ";
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'time',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(),
        ));
        //获取查询结果
        $page = $this->page([
            "table" => self::table,
            "where" => $where,
            "order" => $orderBy['orderBy'],
        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("listForm", "id")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $dominate  = [
                "box" => [
                    "name" => "id",
                    "value" => $array['id']
                ]
            ];
            $opt = '';
            $ico = "<img src='{$this->root}img/svg/file_share.svg' class='right'>";
            $name = $array['name'];
            if ($array['type'] == 'folder') {
                // 图标
                $ico = "<img src='{$this->root}/img/svg/folder_share.svg' class='right'>";
                // 操作
                $opt .=  "<span class='spanA' onclick=\"layer('{$this->get('cla')}', 'editPage', {'id': '{$array['id']}', 'pid': '{$array['pid']}' })\">编辑</span>\n";
                $name = "<a class='hover' onclick=\"refreshNowIframe('{$this->root}control/adIndex.html?cla={$this->get('cla')}&fun=home&pid={$array['id']}')\">{$name}</a>";
                ;
            } else {
                $opt .=  "<span class='spanA' onclick=\"layer('{$this->get('cla')}', 'operate', {'id': '{$array['id']}', 'act': 'range' })\">权限</span>\n";
                $opt .=  "<a class='spanA' target='_blank' href='".root.$array['path']."' download='".$array['name']."' title='".$array['name']."'>下载</a>\n";
                // 预览
                if (in_array($array['suffix'], ['jpg','png','gif', 'jpeg'])) {
                    $opt .=  "<a class='spanA' target='_blank' href='".root.$array['path']."' title='".$array['name']."'>预览</a>\n";
                } elseif (in_array($array['suffix'], ['doc','docx','xls', 'xlsx', 'ppt', 'pptx'])) {
                    $array['format'] = $array['suffix'];
                    $url = $this->wps($array);
                    $opt .= "\n<a class='spanA' target='_blank' href='".$url."' title='".$array['name']."'>预览</a>";
                }
            }
            $liButton[] = $this->dominate($dominate).$ico;
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case 'name':
                        $row[] = $name;
                        break;
                    case 'size':
                        $row[] = self::formatSize($array['size']);
                        break;
                    case 'stid':
                        $row[] = self::findStaff($array['stid']);
                        break;
                    case 'opt':
                        $row[] = $opt;
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = '';
        $fileId = $this->post('fileId');
        $nav    = '<div class="share-nav">' . self::getNavHtml($pid) . '</div>';
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
        //返回
        $json['html'] =
            $nav.
            $page['hint'].
            $button.
            "<form name='listForm' class='share-container'>".
                $li.
            "</form>".
            $page['button'].
            clear .
            $this->uploadHtml($pid, $fileId, $this->root . 'control/adIndex.html?cla=share&fun=chunkUpload') .
            $this->dragUploadHtml($pid, $this->root . 'control/adIndex.html?cla=share&fun=chunkUpload', 'body');
        return json_encode($json, 320);
    }
    private function style(){
        return <<<eof
<style>
.listCheckbox{vertical-align:text-bottom}
</style>
eof;

    }

    public static function getNavArr($pid)
    {
        $temp = $pid . ',';
        $info = query(self::table, " id = '$pid' AND `type` = 'folder' ");
        if ($info['id']) {
            $temp .= $info['pid'] . ',';
            if ($info['pid']) {
                $temp .= self::getNavArr($info['pid']);
            }
        }
        return $temp;
    }

    /**
     * 获取导航条
     *
     * @return string
     */
    public static function getNavHtml($pid):string
    {
        $pidStr = self::getNavArr($pid);
        $temp   = explode(',', trim($pidStr));
        // 倒序
        $temp = array_reverse($temp);
        // 去重
        $array  = array_unique($temp);
        $string = '';
        $href   = "<a class='spanA' onclick=\"refreshNowIframe('" . root . "control/adIndex.html?cla=".self::page."&fun=home&pid={{pid}}');\">{{name}}</a>";
        foreach ($array as $pid) {
            if ($pid == 1) {
                $string .= str_replace(['{{pid}}', '{{name}}'], ['1', '会计电子档案'], $href);
            } else {
                $info = query(self::table, " id = '$pid' ");
                if ($info['id']) {
                    $string .= ' > ' . str_replace(['{{pid}}', '{{name}}'], [$info['id'], $info['name']], $href);
                }
            }
        }
        return $string;
    }


    /**
     * Desc : 显示上传控件
     * User : you name
     * Date : 2024-02-22 11:45
     * @param $pid
     * @param $fileId
     * @param $url
     * @return string
     */
    public function uploadHtml($pid, $fileId, $url)
    {
        $formName = $fileId . 'form';
        return '
            <div class="hide">
                <form name="' . $formName . '" method="post" action="' . root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=upload" enctype="multipart/form-data">
                    <input name="img" type="file" multiple onchange="choiceFileUpload(this, \'' . $pid . '\', \'' . $url . '\')">
                    <input name="pid" type="hidden" value="' . $pid . '">
                </form>
            </div>' .
            "<script>
                function choiceFileUpload(e, pid, url) {
                    var fileList = $(e).prop('files'); //获取文件对象
                    var arr = [];
                    const chunkSize = 5 * 1024 * 1024;
                    $.each(fileList,function(n,file){
                        var value = {
                            'code':  CryptoJS.MD5(file.name + file.size + file.lastModified).toString(),
                            'target':  '1',
                            'name':  file.name,
                            'size':  file.size,
                            'target_id':  pid,
                            'chunks':  Math.ceil(file.size / chunkSize),
                            'power':  'share',
                            'error':  '',
                        }
                        arr.push(value)
                    });
                    $.post(root + 'control/adIndex.html?cla=share&fun=checkUpload', {fileInfo:JSON.stringify(arr)}, function (res) {
                        if(res.warn === 2){
                            layer('share', 'uploadList', {'fileInfo': res.data, 'notClose': 1  })
                            //分片上传
                            for (var i = 0; i < res.data.length; i++) {
                                uploadChunks(fileList[i], res.data[i], url)
                            }
                        }else{
                            msg(res.warn, 'error')
                        }
                    }, 'json')
                }
            </script>";
    }

    // 图片上传
    public function upload()
    {
        $id    = self::getNo();
        $pid   = $this->post('pid') ?? 1;
        $field = [];
        if (!$this->power(self::page, 'edit')) {
            $warn = "你还没有上传的权限";
        } else {
            $pInfo  = query(self::table, " id = '$pid' ");
            $result = $this->saveFile($_FILES['img'], self::table, explode(',', para('fileFormat')));
            if ($result['code']) {
                $field['path']  = $result['src'];
                $field['name'] = $result['fileName'];
                $field['size'] = $result['size'];
                $field['selector'] = $pInfo['selector'];
                $field['member'] = $pInfo['member'];
                $field         = array_merge($field, [
                    'id'     => $id,
                    'coid'=>self::$coid,
                    'pid'    => $pid,
                    'type'   => 'file',
                    'stid'   => self::$stid,
                    'suffix' => $result['suffix'],
                    'time'   => date("Y-m-d H:i:s"),
                ]);
                $warn               = insert([
                    'table' => self::table,
                    'field' => $field
                ]);
                if ($warn == "新增成功") {
                    $warn = "上传成功";
                    //添加日志
                    $text = $this->control['name'] . "上传了了一个共享文件，文件名：【{$field['name']}】, ID【{$id}】";
                    $this->logText(["type" => self::page, "text" => $text]);
                }
            }
        }
        $_SESSION['warn'] = $warn;
        $locationUrl      = root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=home&pid=' . $pid;
        header("location:" . $locationUrl);
        exit(0);
    }

    /**
     * Desc : 拖拽上传
     * User : you name
     * Date : 2024-02-21 09:38
     * @param $pid
     * @param $url
     * @param $node
     * @return string
     */
    public function dragUploadHtml($pid, $url, $node)
    {
        return "
    <div id='windowMaskView' class='maskView'></div>
    <div id='maskViewContent' class='viewContent'>
        <div class='content-div'>
            <div class='upload-tips'>						
                <div class='cloud-icon'>							
                    <i class='icon-cloud cloud1 moveLeftLoop'></i>
                    <i class='icon-cloud cloud2'></i>
                    <i class='icon-cloud cloud3 moveLeftLoop'></i>
                </div>
                <div class='cloud-moveup'>
                    <i class='moveTopLoop icon-circle-arrow-up'></i>
                </div>						
                <div class='msg'>松开即可上传!</div>
            </div>
        </div>
    </div>
    <script>
        var pid = '{$pid}'
        var url = '{$url}'
        var node = '{$node}'
        $(document).ready(function(){
            let elemetnNode=''//最后一次节点
            //要想实现拖拽，首页需要阻止浏览器默认行为，一个四个事件。
            $('#'+node).on({
                dragleave:function(e){		//拖离
                    e.preventDefault();     //移除原有浏览器监听效果
                    if(elemetnNode===e.target)
                    $('.maskView,.viewContent').removeClass('over');
                },
                drop:function(e){			//拖后放
                    e.preventDefault();     //移除原有浏览器监听效果
                },
                dragenter:function(e){		//拖进
                    elemetnNode=e.target;
                    e.preventDefault();     //移除原有浏览器监听效果
                    $('.maskView,.viewContent').addClass('over');
                },
                dragover:function(e){		//拖来拖去
                    e.preventDefault();     //移除原有浏览器监听效果
                    $('.maskView,.viewContent').addClass('over');
                }
            });
            
            //================上传的实现
            var box = document.getElementById(node); //获得到框体
            var newHandle = function(e){
                e.preventDefault(); //取消默认浏览器拖拽效果
                e.stopPropagation()
                var fileList = e.dataTransfer.files; //获取文件对象
                //fileList.length 用来获取文件的长度（其实是获得文件数量）
                console.log(fileList)
                
                //检测是否是拖拽文件到页面的操作
                if(fileList.length == 0){
                    $('.maskView,.viewContent').removeClass('over');
                    return;
                }
                var arr = [];
                const chunkSize = 5 * 1024 * 1024;
                $.each(fileList,function(n,file){
                    var value = {
                        'code':  CryptoJS.MD5(file.name + file.size + file.lastModified).toString(),
                        'target':  '1',
                        'name':  file.name,
                        'size':  file.size,
                        'target_id':  pid,
                        'chunks':  Math.ceil(file.size / chunkSize),
                        'power':  'share',
                        'error':  '',
                    }
                    arr.push(value)
                });
                $.post(root + 'control/adIndex.html?cla=share&fun=checkUpload', {fileInfo:JSON.stringify(arr)}, function (res) {
                    $('.maskView,.viewContent').removeClass('over');
                    if(res.warn === 2){
                        layer('share', 'uploadList', {'fileInfo': res.data, 'notClose': 1 })
                        //分片上传
                        for (var i = 0; i < res.data.length; i++) {
                            uploadChunks(fileList[i], res.data[i], url)
                        }
                        box.removeEventListener(\"drop\",newHandle);
                    }else{
                        msg(res.warn, 'error')
                    }
                }, 'json')
            }
            box.addEventListener(\"drop\",newHandle,false);
        });
            
    </script>";
    }

    public function editPage()
    {
        $info = query(self::table, " id = '".$this->post('id')."' ");
        $html = $this->layerEdit([
            "table" =>[
                [
                    must."文件夹名称" => text(['name'=>'name', 'value'=> $info['name'], 'class'=>'text width300' ]),
                ],
                [
                    '查看范围' =>componentClass::staffSelector($info['selector']),
                ],
                [
                    "备注" => textarea(['name'=>'text', 'value'=> $info['text'], 'class'=>'text' ]).hidden(['name'=>'pid', 'value'=> $info['pid'] ? $info['pid'] : $this->post('pid') ]),
                ]
            ]
        ]);
        return $this->layer(array("title" => "编辑".self::title,"height" => 450,"width" => 1000,"html" => $html));
    }

    /*成本表基本资料新增或修改-异步处理*/
    public function editPageEdit()
    {
        $id = $this->post('id') ?? self::getNo();
        $field = [
            'pid'       => $this->post('pid') ?? 1,
            'type'      => 'folder',
            'name'      => $this->post('name'),
            'selector'       => $this->post('staff')[0]??'',//员工选择器
            'text'      => $this->post('text'),
        ];
        $staff = componentClass::returnStaffId($field['selector']);
        $field['member'] = implode(',',$staff);
        $annotation = [
            'pid'       => '上级ID',
            'type'      => '类型',
            'name'      => '文件名',
            'text'      => '备注',
        ];
        $rules = [
            'pid'       => 'required|unsigned_int',
            'type'      => 'required',
            'name'      => 'required',
        ];
        // 校验是否符合规则
        $vt     = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0]; // 多个规则提示最前面一条
            goto resp;
        }
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = "你没有编辑".self::title."的权限";
        } else {
            $where = " id = '$id' ";
            $info = query(self::table, $where);
            if (sqlNum(self::table, "coid = '".self::$coid."' and pid = '{$field['pid']}' AND name = '{$field['name']}' AND id != '$id'   ") > 0) {
                $json['warn'] = "当前层级下已存在该目录【{$field['name']}】";
                goto resp;
            }

            if (!$info['id']) {
                $field    = array_merge($field, [
                    'id'      => $id,
                    'coid'=>self::$coid,
                    'stid'     => self::$stid,
                ]);
                $json['warn'] = static::insert(["table" => self::table, "field" => $field,]);
            } else {
                $json['warn'] = static::update([
                    "table" => self::table,
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                //添加日志
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了".self::title." id：【" . $id.'】';
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn']     = 2;
                $json['href'] = root . "control/adIndex.html?cla=".$this->get('cla')."&fun=home&pid=" . $field['pid'];
            }
        }

        resp:
        return json_encode($json, 320);
    }

    public static function getLevelAll($data = [])
    {
        $idColloection = self::$idColloection;
        $viewWhere = " AND if(selector is null,'1=1',((concat(',',replace(selector,';',','),',') regexp concat(',',replace('{$idColloection}',',',',|,'),','))>0 OR stid = '".self::$stid."'))";
        // 条件
        $data['where'] = $data['where'] ?? "pid='1'";
        // 点击事件
        $data['click'] = $data['click'] ?? 'selection(this, \'pid\')';
        // 结果
        $result = find(['table' =>self::table, 'where'=> $data['where'] .$viewWhere."  AND `type` = 'folder' and coid = '".self::$coid."' " ]);
        $style = ($data['where'] == "pid='1'") ? '' : ' class="child-node"';
        $temp = "<ul {$style} {$data['where']}>";
        // 角标
        $arrow = "<span class='arrow' onclick=\"liZoom($(this).parent())\"></span>";
        $lastone = lastone;
        $textcontent_ico = "<span class='textcontent_ico'></span>";
        if(empty($style)) {
            $temp .= "<li data-id='1' onclick=\"selection(this, 'pid')\">$arrow <span class='textcontent'>{$textcontent_ico}根目录</span></li>";
            $temp   .= "<ul class='child-node' pid='1'>";
        }
        if ($result['array']) {
            foreach ($result['array'] as $value) {
                // 判断下级是否存在
                $data['where'] = " pid='{$value['id']}' AND `type` = 'folder'";
                $has = query(self::table, $data['where'].$viewWhere);
                if ($has) {
                    $temp .= "<li data-id='{$value['id']}' onclick=\"{$data['click']}\">$arrow <span class='textcontent'>{$textcontent_ico}{$value['name']}</span></li>";
                    $temp .= self::getLevelAll($data);
                } else {
                    $temp .= "<li data-id='{$value['id']}' onclick=\"{$data['click']}\">$lastone <span class='textcontent'>{$textcontent_ico}{$value['name']}</span></li>";
                }
            }
        }
        $temp .= '</ul>';
        return $temp;
    }

    /**
     * 移动文件夹 下拉
     *
     * @return string
     */
    public function moveHtml():string
    {
        self::$idColloection =  $this->staffCombination(true);
        $search          = "<div class='container-left-search-parent flex-box'>
                                ".text(["name" => 'name', 'title' => "搜索文件夹", 'class' => 'container-left-search', 'other' => " onkeyup='search_left(this,event)' "])."
                                <i class='container-left-search-ico' onclick=\"search_left(document.getElementsByClassName('container-left-search')[0])\"></i>
                                <span class='search-count'></span>
                            </div>";
        $all = self::getLevelAll();
        return <<<efo
                    <div class="layer-container-main">
                        <div class="container-left" id="container-left">
                          {$search}
                           <div class="classify-area">
                                $all
                            </div>
                        </div>
                    </div>
<script>
$(document).ready(function(){
    //初始化左侧分类标记和定位
    search_left(document.getElementsByClassName('container-left-search')[0])
});
</script>
<style>
.layer-container-main .container-left{height: 235px;flex: 1;}
.layer-container-main .container-left .classify-area {height: 205px;overflow: auto;}
</style>
efo;
    }

    // 操作中转
    public function operate()
    {
        $act = $this->post('act') ?? '';
        $pwd = $height = false; // 需要密码、 指定高度
        $form = $power = '';
        $append = [];
        switch ($act) {
            case 'range':
            // 移动
            case 'move':
                $act = 'edit';
                $msg = self::title.'修改状态';
                $title = '';
                $function = 'moveData';
                $form = self::page.'OperateForm, listForm';
                $append = [
                    $this->moveHtml().hidden(['name'=>'pid', 'id'=>'pid'])
                ];
                $height = 340;
                break;
            default:
                $act = 'del';
                $msg = '删除'.self::title;
                $title = self::page.'Delete';
                $function = 'isDelete';
                $form = 'shareOperateForm, listForm';
                $power = '';
                break;
        }
        if (!$this->power(self::page, $act)) {
            $_SESSION['warn'] = '你还没有' . $msg . '的权限';
            $json             = [
                'warn' => 2,
                'href' => root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=home',
            ];
        } else {
            return $this->confirm([
                'title'    => $title,
                'function' => $function,
                'form'     => $form,
                'power'    => $power,
                'pwd'      => $pwd,
                'append'   => $append,
                'height'   => $height
            ]);
        }

        resp:
        return json_encode($json, 320);
    }


    // 确认删除信息
    public function isDelete()
    {
        $array = $this->post('listId') ?? $this->post('id');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = "你没有删除".self::title."的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一条记录都没有选择呢";
        } else {
            $text = '';
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $where = " id = '$id' ";
                $info = query(self::table, $where);
                if ($info['id']) {
                    // 删除表
                    delete([
                        "table" => self::table,
                        "where" => $where
                    ]);
                    fileDelete($info['path']);
                    //添加记录
                    $text .= "管理员{$this->control['name']}删除了一个".self::title."：ID【{$id}】<br>";
                    $x++;
                }
            }
            // 写入日志
            $this->logText(["type" => self::page, "text" => $text]);
            $_SESSION['warn'] = "删除了{$x}条".self::title;
            $json['warn']     = 2;
            $json['href'] = root."control/adIndex.html?cla=".$this->get('cla')."&fun=home";
        }

        resp:
        return json_encode($json, 320);
    }

    /**
     * 移动函数
     */
    public function moveData()
    {
        $array = $this->post('listId') ?? $this->post('id');
        $pid = $this->post('pid');
        $act = 'edit';
        $json = [];
        if (!$this->power(self::page, $act)) {
            $json['warn'] = "你没有此权限的权限";
        } elseif (empty($array)) {
            $json['warn'] = "你一条记录都没有选择呢";
        } elseif (empty($pid)) {
            $json['warn'] = "请选择你要移动的文件夹";
        } else {
            $text = '';
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            // 修改field
            foreach ($array as $id) {
                $where = " id = '$id' ";
                $info = query(self::table, $where);
                if($info['stid'] != self::$stid){
                    $text .= "{$this->control['name']}非文件：ID【{$id}】".(!static::isNull($info['name']) ? "，文件名【{$info['name']}】" : '').'创建者，无法移动<br>';
                    continue;
                }
                if ($info['id'] && $info['pid'] != $pid) {
                    // 修改状态
                    static::update([
                        "table" => self::table,
                        'field' => [
                            'pid' => $pid,
                        ],
                        "where" => $where
                    ]);
                    //添加记录
                    $text .= "{$this->control['name']}移动了文件：ID【{$id}】".(!static::isNull($info['name']) ? "，文件名【{$info['name']}】" : '').'<br>';
                    $x++;
                }
            }
            // 写入日志
            $this->logText(["type" => self::page, "text" => $text]);
            $_SESSION['warn'] = "移动了{$x}个文件（夹）";
            $json['warn']     = 2;
            $json['href'] = root."control/adIndex.html?cla=".$this->get('cla')."&fun=home";
        }
        resp:
        return json_encode($json, 320);
    }

}
